invalid operands of types `int' and `int ()(int)' to binary `operator-'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • categami
    New Member
    • Feb 2012
    • 9

    invalid operands of types `int' and `int ()(int)' to binary `operator-'

    hey i need help with this

    this error keeps popping up on line 20 invalid operands of types `int' and `int ()(int)' to binary `operator-'
    is there any help i can get please help me!!!
    thank you so much.

    im sorry if i broke any rules but im getting desperate right now. i searched every where but i cant find the answer for it so please help me.

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int h(int h=100);
    
    int l(int l = 10);
    
    int d(int d = 0);
    
    int subtraction (int h, int l);
    
    int subtraction (int h, int d)
    
    {
        if (h)
        {
        return h - l;
        }
        else 
        {
             if (d)
             {
                 return h - d;
             }
        }
    }
    int main(int arg, char *argv[])
    {
         int d;
         int l;
         int h;
            //damage
            if ( 1 == 1)
            {
                  cout << subtraction (h, l) << endl;
            }
            else
            {
                if ( 1 == 2)
                {
                       cout << subtraction(h, l) << endl;
                }
                else
                {
                    if ( 1 == 3)
                    {
                          cout << subtraction(h, l) << endl;
                    }
                    else
                    {
                        if ( 1 == 4)
                        {
                              cout << subtraction(h, l) << endl;
                        }
                        else
                        {
                            if ( 1 == 5)
                            {
                                  cout <<  subtraction(h, d) << endl;
                            }
                        }
                    }
                 }
             }
                  if ( 2 == 1)
            {
                  cout << subtraction(h, l) << endl;
            }
            else
            {
                if ( 2 == 2)
                {
                       cout << subtraction(h, l) << endl;
                }
                else
                {
                    if ( 2 == 3)
                    {
                          cout << subtraction(h, l) << endl;
                    }
                    else
                    {
                        if ( 2 == 4)
                        {
                              cout << subtraction(h, l) << endl;
                        }
                        else
                        {
                            if ( 2 == 5)
                            {
                                  cout <<  subtraction(h, d) << endl;
                            }
                        }
                    }
                }
             }
                     if ( 3 == 1)
            {
                  cout << subtraction(h, l) << endl;
            }
            else
            {
                if ( 3 == 2)
                {
                       cout << subtraction(h, l) << endl;
                }
                else
                {
                    if ( 3 == 3)
                    {
                          cout << subtraction(h, d) << endl;
                    }
                    else
                    {
                        if ( 3 == 4)
                        {
                              cout << subtraction(h, d) << endl;
                        }
                        else
                        {
                            if ( 3 == 5)
                            {
                                  cout <<  subtraction(h, l) << endl;
                            }
                        }
                    }
                }
            }
                     if ( 4 == 1)
            {
                  cout << subtraction(h, l) << endl;
            }
            else
            {
                if ( 4 == 2)
                {
                       cout << subtraction(h, l) << endl;
                }
                else
                {
                    if ( 4 == 3)
                    {
                          cout << subtraction(h, d) << endl;
                    }
                    else
                    {
                        if ( 4 == 4)
                        {
                              cout << subtraction(h, d) << endl;
                        }
                        else
                        {
                            if ( 4 == 5)
                            {
                                  cout <<  subtraction(h, l) << endl;
                            }
                        }
                    }
                }
            }
                     if ( 5 == 1)
            {
                  cout << subtraction(h, d) << endl;
            }
            else
            {
                if ( 5 == 2)
                {
                       cout << subtraction(h, d) << endl;
                }
                else
                {
                    if ( 5 == 3)
                    {
                          cout << subtraction(h, l) << endl;
                    }
                    else
                    {
                        if ( 5 == 4)
                        {
                              cout << subtraction(h, l) << endl;
                        }
                        else
                        {
                            if ( 5 == 5)
                            {
                                  cout <<  subtraction(h, d) << endl;
                            }
                        }
                    }
                }
            }
        system("PAUSE");
        return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You have not defined these functions:

    int h(int h=100);

    int l(int l = 10);

    int d(int d = 0);

    Comment

    • categami
      New Member
      • Feb 2012
      • 9

      #3
      they should be defined in lines 32-34

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        These are variables:
        Code:
             int d;
         33.      int l;
         34.      int h;
        These are functions:
        Code:
        int h(int h=100);
         8. 
         9. int l(int l = 10);
         10. 
         11. int d(int d = 0);
        You will find that using a variable with the same name as a function will cause your code to not compile. What's saving you now is that you are never calling the functions.

        I expect you mean to do something else. Like create an integer h with an initial value of 100. Tha would look like:

        Code:
        int main()
        {
            int h = 100;
            etc...

        Comment

        • categami
          New Member
          • Feb 2012
          • 9

          #5
          so this is the int h being called on

          Code:
           int main()
          {
              int h = 100;
              etc...
          and i did not properly call my functions the way i need them to be

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            You are not calling a function here. What this does is set a variable to a value of 100.

            All function calls in C and C++ use parentheses to enclose the arguments, if there are any.

            Code:
            int h = 100;  //variable
            void x(int y);      //function;
            You do not call variables.

            Comment

            • categami
              New Member
              • Feb 2012
              • 9

              #7
              sorry as you can tell im very new to c++ i have blood shed
              so how would i call the function properly then

              Comment

              • whodgson
                Contributor
                • Jan 2007
                • 542

                #8
                Just by name and argument/s.
                In weaknessforcats last post:
                Code:
                 x(y);

                Comment

                • categami
                  New Member
                  • Feb 2012
                  • 9

                  #9
                  i have one other question there are 3 varibles how would i set a arguments of some sort cause its sopose to do this if it is not damaging the person then it should call on another equation in the if statement i have set up

                  Code:
                  int h(int h=100);
                   
                  int l(int l = 10);
                   
                  int d(int d = 0);
                   
                  int subtraction (int h, int l);
                   
                  int subtraction (int h, int d)
                   
                  {
                      if (h)
                      {
                      return h - l;
                      }
                      else 
                      {
                           if (d)
                           {
                               return h - d;
                           }
                      }
                  }

                  Comment

                  • weaknessforcats
                    Recognized Expert Expert
                    • Mar 2007
                    • 9214

                    #10
                    I am having trouble understanding your English. Please try to explain again.

                    Comment

                    • categami
                      New Member
                      • Feb 2012
                      • 9

                      #11
                      in this code i am trying to make 2 different equations get used. the first equation is for health lost.
                      the second equation deals with when the person blocks which is int d so it makes it where health is not lost
                      i need to figure out how to make 3 varibles into a argument stating "if he attacks and health is lost do the first equation if he blocks do the second equation"

                      Code:
                      int h(int h=100);
                       
                      int l(int l = 10);
                       
                      int d(int d = 0);
                       
                      int subtraction (int h, int l);
                       
                      int subtraction (int h, int d)
                       
                      {
                          if (h)
                          {
                          return h - l;
                          }
                          else 
                          {
                               if (d)
                               {
                                   return h - d;
                               }
                          }
                      }
                      the first equation
                      Code:
                      int h(int h=100);
                       
                      int l(int l = 10);
                      
                      int subtraction (int h, int l);
                       
                      return h - l;
                      second equation

                      Code:
                      int l(int l = 10);
                      
                      int D(int D = 0);
                      
                      
                      int subtraction (int h, int d)
                      
                      return h - d;

                      Comment

                      • weaknessforcats
                        Recognized Expert Expert
                        • Mar 2007
                        • 9214

                        #12
                        OK, here is what you said:

                        "if he attacks and health is lost do the first equation if he blocks do the second equation"

                        In C++ this looks like:

                        Code:
                        if (he == attacks)
                        {
                            if (health == lost)
                            {
                                Do the first equation.
                            }
                        }
                        if (he == blocks)
                        {
                            Do the second equation.
                        }
                        You will need variables for the patient, and values for what "attacks" and "blocks" means.

                        You may also need more information about your patient:

                        Code:
                        struct Patient
                        {
                          bool Health;  //if true patient has health
                          bool Heart;   //if true patient has had an attack
                          bool Blocks;  //if true patient has blocked
                        };

                        Comment

                        • categami
                          New Member
                          • Feb 2012
                          • 9

                          #13
                          crap umm what do you mean by patient?
                          this whole thing is a text based game i had to divide it into different source files so it would be less complicated

                          the first code is basicly what i need it to say but when i do the other if statements it makes a ton of errors do i have to add the word to it as well cause all i want it to do is when one person types all they have to do is type in a number and hit enter. but with the attack i think it will make them have to type in "attack 1" if that makes any sense at all to you.

                          and i dont know what you mean by the bool statements either can explain that please

                          Comment

                          • weaknessforcats
                            Recognized Expert Expert
                            • Mar 2007
                            • 9214

                            #14
                            I was trying to guess what you are trying to do in the absence of information.

                            "attack". "health and "blocks" are common medical terms so I assumed you were doing some sort of patient analysis.

                            I think the best thing to do here is to stop and let you explain what it is you are doing. Have you any experience at all in programming?

                            Comment

                            • categami
                              New Member
                              • Feb 2012
                              • 9

                              #15
                              i have very little experience im doing this to make myself have more experience and so i can learn the functions and other stuff i havnt been able to learn from the internet or my book c++ for dumbies

                              this is what im doing. its a fight based text game it will pop up with beginning text giving the person instructions as to how to play then say
                              "player 1" the person that player 1 will type in a number from 1 - 5
                              then it will say "player 2" he will do the same thing.
                              once they do that it must calculate the infermation it is giving example would be.
                              player 1
                              1
                              player 2
                              1
                              health 90 points

                              thats for attack based
                              for deffence is

                              player 1
                              1
                              player 2
                              5
                              health 100 points

                              and they will keep doing this until some one hits zero.

                              Comment

                              Working...